﻿#include "radar_shujv_jilu.h"
#include "ui_radar_shujv_jilu.h"

radar_shujv_jilu::radar_shujv_jilu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::radar_shujv_jilu)
{
    ui->setupUi(this);
    this->setWindowTitle("cat240_8K_视频数据存储回放工具");
    receiver=new UdpMulticastReceiver();

    connect(ui->pushButton, &QPushButton::clicked, this, &radar_shujv_jilu::onPushButtonClicked_jieshou);
    connect(ui->pushButton_2, &QPushButton::clicked, this, &radar_shujv_jilu::onPushButtonClicked_fasong);
    connect(ui->openButton, &QPushButton::clicked, this, &radar_shujv_jilu::openFile);
    clickCount=0;
}

radar_shujv_jilu::~radar_shujv_jilu()
{
    delete ui;
}

void radar_shujv_jilu::onPushButtonClicked_jieshou()
{
    clickCount++;

    if (clickCount % 2 == 0) {
        receiver->stop_wt();
        ui->pushButton->setText("开始记录");

    } else {
        QString IP = ui->lineEdit->text();
        quint16 port = static_cast<quint16>(ui->spinBox->value());
        if(IP=="")
        {
            QMessageBox::information(this, "提示", "请输入正确的IP号");
            return;
        }
        if(port==0)
        {
            QMessageBox::information(this, "提示", "请输入正确的端口号");
            return;
        }
        receiver->start(IP,port);
        receiver->start_wt();
        ui->pushButton->setText("停止记录");
    }

}
void radar_shujv_jilu::onPushButtonClicked_fasong()
{
    QString IP = ui->lineEdit_2->text();
    QHostAddress hostAddress(IP);
    quint16 port = static_cast<quint16>(ui->spinBox_2->value());
    if(IP=="")
    {
        QMessageBox::information(this, "", "");
        return;
    }
    if(port==0)
    {

        QMessageBox::information(this, "", "");
        return;
    }
    sender=new FileSender(hostAddress,port);
}
void radar_shujv_jilu::openFile() {


    QString filePath = QFileDialog::getOpenFileName(this, "Open File", QDir::currentPath());
    if (filePath.isEmpty()) {
        qDebug() << "No file selected.";
        return;
    }
    sender->startSending(filePath);
}
